package ua.org.extjsbuilder.editors;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.swt.SWT;

public class JSKeywordsScanner extends RuleBasedScanner {
	private final static String JS_ALLOWED_CHARS = "[a-zA-Z0-9$]";
	//TODO: move to the global constants
	public final static String JS_KEYWORDS_PATTERN = "var|const|function|for|in|while|" +
		"do|if|else|instanceof|break|continue|return|switch|case|default|try|catch|finally|" +
		"boolean|Number|int|new|delete|false|true|null|undefined|this|typeof|void|with";
	
	JSKeywordsScanner(ColorManager manager){
		IToken kw = new Token(new TextAttribute(
			manager.getColor(ColorManager.KEYWORD),null,SWT.BOLD));

		IRule[] rules = new IRule[1];
		rules[0] = new PatternMatchRule(JS_KEYWORDS_PATTERN,JS_ALLOWED_CHARS,kw);
		setRules(rules);
	}
}
